#include "Col.ph"
#ifdef __GNUG__
#pragma implementation
#endif

#include "Math.h"

#include "ET_math.h"

#ifdef sun
	extern "C" void sincos(double, double*, double*);
#else
	inline void sincos(double a, double *sinp, double *cosp)
		{ *cosp= cos(a); *sinp= sin(a); }
#endif

#ifdef macintosh
	double hypot(double, double)
	{ return 0.0; }
#endif

const double
	Math::Pi = 3.14159265358979323846,
	Math::E  = 2.7182818284590452354;

int Math::Sqrt(int x)
{
	return (int) (sqrt(x) + 0.5);
}

double Math::Sqrt(double x)
{
	return sqrt(x);
}

int Math::Hypot(int x, int y)     // return sqrt(px*px + py*py);
{
	return (int) (hypot(x, y) + 0.5);
}

double Math::Hypot(double x, double y)
{
	return hypot(x, y);
}

double Math::Sin(double x)
{
	return sin(x);
}

double Math::Cos(double x)
{
	return cos(x);
}

double Math::ASin(double x)
{
	return asin(x);
}

double Math::ACos(double x)
{
	return acos(x);
}

double Math::ATan(double x)
{
	return atan(x);
}

double Math::ATan2(double x, double y)
{
	return atan2(x, y);
}

double Math::Ceil(double x)
{
	return ceil(x);
}

double Math::Floor(double x)
{
	return floor(x);
}

double Math::Exp(double x)
{
	return exp(x);
}

double Math::Power(double x, double y)
{
	return pow(x, y);
}

double Math::Atan2(int y, int x)
{
	double dd= (0.75 - (atan2(-y, x) / Math::Pi + 1.0)/2.0 ) * 360.0;
	while (dd < 0.0)
		dd+= 360.0;
	return dd;
}

double Atan2(double fy, double fx)
{
	return Math::Atan2((int)(fy+0.5), (int)(fx+0.5));
}

void Math::Sincos(double a, double *sinp, double *cosp)
{
	sincos(2 * Math::Pi * (90.0 - a) / 360.0, sinp, cosp);
	*sinp= -*sinp;
}

int Math::NextPrime(int x)
{
	if (x <= 3)
		return 3;

	if (x % 2 == 0)
		x++;

	int sqr= (int) sqrt((double)x) + 1;

	for (;;) {
		for (int n= 3; (n <= sqr) && ((x % n) != 0); n+= 2)
			;
		if (n > sqr)
			return x;
		x+= 2;
	}
}

